/**
 * Copyright 2011 Aaron Zeckoski
 * This file is part of Maven Exercise 6.
 *
 * Maven Exercise 6 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Maven Exercise 6 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Maven Exercise 6.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.az.dao;

import java.io.Serializable;
import java.util.List;

/**
 * Based on http://community.jboss.org/docs/DOC-13955
 * @param <T> entity type
 * @param <ID> primary key
 *
 * @see org.az.server.dao.impl.GenericHibernateDAOImpl
 */
public interface GenericDAO<T, ID extends Serializable> {

    /**
     * @param id the unique id (primary key) of the entity
     * @param lock
     * @return
     */
    T findById(ID id, boolean lock);

    /**
     * @param maxLimit the maximum items to return (0 for all)
     * @param orderFieldName the field to sort by (defaults to database natural order)
     * @param orderAscending the sort order to use (true for ascending, false for descending)
     * @return the list of all items of this type
     */
    public List<T> findAll(int maxLimit, String orderFieldName, boolean orderAscending);

    /**
     * Allows exact searching via sample field values,
     * other searches will have to be custom built methods when extending the generic DAO
     * 
     * @param exampleInstance
     * @param excludeProperty
     * @return list of matching items
     */
    List<T> findByExample(T exampleInstance, String[] excludeProperty);

    /**
     * Save this entity (update or create)
     * @param entity
     * @return the persistent entity object
     */
    T save(T entity);

    /**
     * Remove this entity
     * @param entity
     */
    void remove(T entity);

}
